//
//  JXTabBarViewController.swift
//  swift高仿微博
//
//  Created by peijiaxing on 16/2/24.
//  Copyright © 2016年 peijiaxing. All rights reserved.
//

import UIKit

class JXTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabbar = JXTabBar()
        
        setValue(tabbar, forKey: "tabBar")
        
        tabbar.composeButton.addTarget(self, action: "click", forControlEvents: UIControlEvents.TouchUpInside)
        
       addChildViewController()
 
    }
    func click (){
        
        print("点击")
        let publish = JXPublishViewController()
        
        let nav = UINavigationController(rootViewController: publish)
        
        presentViewController(nav, animated: true) { () -> Void in
            
        }
        
    }
    
    // addChildViewController -- 重载
    func addChildViewController() {
        
        addChildViewController(JXHomeViewController(), title: "首页", image: "tabbar_home")
        addChildViewController(JXMessageViewController(), title: "消息", image: "tabbar_message_center")
        addChildViewController(JXFindViewController(), title: "发现", image: "tabbar_discover")
        addChildViewController(JXSettingViewController(), title: "设置", image: "tabbar_profile")
        
        
    }
    
    // 给 addChildViewController 方法添加了参数-- 重载
    func addChildViewController(childController: UIViewController,title:String,image:String) {
        
        // 设置文字
        childController.title = title
        // 设置图片
        childController.tabBarItem.image = UIImage(named: image)
        childController.tabBarItem.selectedImage = UIImage(named: "\(image)_highlighted")
        
        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        addChildViewController(UINavigationController(rootViewController: childController))

        
        
    }
    
}
